﻿<%@ Page Language="C#" %>

<%@ Import Namespace="System.Collections.Generic" %>
<%
    if (Session["_User"] == null)
    {
        Response.Redirect("../login.aspx", true);
    }
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <title>WebGIS</title>
    <link rel="stylesheet" href="theme/default/style.css" type="text/css" />
    <link rel="stylesheet" type="text/css" href="ext/resources/css/ext-all.css" />
    <link rel="stylesheet" type="text/css" href="gis.css" />
    <link rel="stylesheet" type="text/css" href="ext-patch.css" />
    <link rel="stylesheet" type="text/css" href="ext/resources/css/file-upload.css" />

    <script type="text/javascript" src="Charts/FusionCharts.js"></script>

    <script type="text/javascript" src="ext/adapter/ext/ext-base.js"></script>

    <script type="text/javascript" src="ext/ext-all.js"></script>

    <script type="text/javascript" src="OpenLayers.js"></script>

    <script type="text/javascript" src="OpenLayersExtends.js"></script>

    <script language="text/javascript" type="text/javascript">    
        var map,vlayer,noeditvlayer,drawlayer,toolbar;               //overviewmap
        var devicelayername = 'TAB_DEVICE',overlinelayername = 'TAB_OVERLINE',towerlayername = 'TAB_TOWER';
        var geoserverurl = "http://" + document.location.hostname + ":8888/mapviewer/wms";
        var towerlayer,overlinelayer,wirelayer,devicelayer;
        var pgoogle = new OpenLayers.Projection("EPSG:4326");
        var pdis = new OpenLayers.Projection("EPSG:4326");
        var itemcount = 0;    
        var GeoStyle = {
            insert:{
            pointRadius: 6,
                            strokeWidth: 2,
                            strokeOpacity: 1,
                            strokeColor: "red",
                            fillColor: "white",
                            fillOpacity: 0.5,
                            strokeDashstyle:'dot'
                            
                        },
            update:{
                            pointRadius: 6,
                            strokeWidth: 4,
                            strokeOpacity: 1,
                            strokeColor: "#FF3300",
                            fillColor: "red",
                            fillOpacity: 0.5,
                            strokeDashstyle:'solid'
                        },
            del:{
            pointRadius: 6,
                            strokeWidth: 2,
                            strokeOpacity: 1,
                            strokeColor: "black",
                            fillColor: "white",
                            fillOpacity: 0.5,
                            strokeDashstyle:'dot'
                        },                
             normal:{
                        pointRadius: 6,
                            strokeWidth: 2,
                            strokeOpacity: 1,
                            strokeColor: "orange",
                            fillColor: "orange",
                            fillOpacity: 0.5,
                            strokeDashstyle:'solid'
                        }                  ,
            highlight:{
                        pointRadius: 8,
                            strokeWidth: 4,
                            strokeOpacity: 1,
                            strokeColor: "green",
                            fillColor: "white",
                            fillOpacity: 0.5,
                            strokeDashstyle:'solid'
                        } ,
            focus:{
                        pointRadius: 10,
                            strokeWidth: 5,
                            strokeOpacity: 1,
                            strokeColor: "red",
                            fillColor: "white",
                            fillOpacity: 0.5,
                            strokeDashstyle:'solid'
                        }                                                                  
        };

        function queryTowerByPolygon(feature){
            var bounds = feature.geometry.transform(pgoogle,pdis).getBounds();
            var minx = bounds.left;
            var maxx = bounds.right;
            var miny = bounds.bottom;
            var maxy = bounds.top;        
            document.getElementById("ContFrame").src = "../Public/CommonPage.aspx?table=TAB_TOWER&tabsysid=36&initWhere=a.latitude between " + miny + " and " + maxy + " and a.longitude between " + minx + " and " + maxx;
        }  	
        function queryOverlineByPolygon(feature){
            var wkt = feature.geometry.transform(pgoogle,pdis).toString();
            document.getElementById("ContFrame").src = "../Public/CommonPage.aspx?table=TAB_OVERLINE&tabsysid=34&initWhere=a.shape is not null and SDO_GEOM.RELATE(a.shape,'ANYINTERACT',sdo_geometry('"+wkt+"',4326),0.00005) LIKE 'TRUE'";
        }  	
        function showEditVectors(tablecode,objs){
            clearEditVectors();
            foreach(obj in objs)
            {
                addEditVector(obj.tablecode,obj.condition,obj.wkt);
            }
        }
        function clearHightLightedVectors(){
            vlayer.removeAllFeatures();
            noeditvlayer.removeAllFeatures();
        }
        function showHightLightedVector(tablecode,condition,wkt){
            var vector = new OpenLayers.Feature.Vector(OpenLayers. Geometry. fromWKT(wkt),{tablecode:tablecode,condition:condition,state:''},GeoStyle.highlight);
            if(vector.geometry instanceof OpenLayers.Geometry.Point){
                vlayer.addFeatures(vector);
            }
            else{
                noeditvlayer.addFeatures(vector);
            }
        }
        function savemodify(){            
            var index = "";
            var condition="";
            var longitude = "";
            var latitude = "";            
            for(var i = 0; i < vlayer.features.length;i++){
                var fea = vlayer.features[i];
                if(fea.attributes.state == 'modify'){                    
                    index += i + ",";
                    condition += fea.attributes.condition + ",";
                    longitude += fea.geometry.x + ",";
                    latitude += fea.geometry.y + ",";                    
                }
            }
            if(index.length == 0)
            return;
            else{
            if(!window.confirm("是否要保存？")){return;}    
            }
            index = index.replace(/,$/,'');
            condition = condition.replace(/,$/,'');
            longitude = longitude.replace(/,$/,'');
            latitude = latitude.replace(/,$/,'');            
            Ext.Ajax.request({
                       url: 'aspx/updateshape.aspx?tablecode='+fea.attributes.tablecode+'&index='+index+'&condition=' + condition,
                       success: function(response,opts){clearfeatures(response.responseText),overlinelayer.redraw(true);},
                       failure: function(response,opts){alert('更新坐标出错！');},
                       params: { longitude: longitude,latitude:latitude }
                    });
            
        }
        function clearfeatures(indexs){
                var array = eval(indexs);               
                for(var i=0;i < array.length;i++){                    
                    var fea1 = vlayer.features[array[i]];
                    fea1.style = GeoStyle.highlight;
                    vlayer.drawFeature(fea1);
                    try{
                        fea1.attributes.state = '';
                    }
                    catch(e){}   
                    
                }
        }

        var wincolumn;
        var winrow;
        Ext.onReady(function(){
            init();           
        });
        //纵断面分析                               
        function ColumnCutAnalysis(fea){
            showcolumncut('aspx/columncut.aspx?x=' + fea.geometry.x + '&y=' + fea.geometry.y + '&r=' + map.resolution * 5);
        }
        //横断面分析
        function RowCutAnalysis(overlineid,startorder,endorder){            
            showrowcut('aspx/rowcut.aspx?overlineid=' + overlineid + '&startorder=' + startorder + '&endorder=' + endorder);            
        }
        function showcolumncut(url){     
            if(!wincolumn)
            {               
                var myChart2 = new FusionCharts( "Charts/Bubble.swf", "columncut2", "100%", "100%", "0", "1" );                
                myChart2.render("columncut");
                wincolumn = new Ext.Window({
                    applyTo:'column-container',
                    layout:'fit',
                    width:520,
                    height:352,
                    closeAction:'hide',
                    plain: true,
                    items: new Ext.TabPanel({
                        applyTo:'columncut',
                        autoTabs:true,
                        activeTab:0,
                        deferredRender:false,
                        border:false
                    }),

                    buttons: [{
                            text: '关闭',
                            handler: function(){
                                wincolumn.hide(document.body);
                            }
                        }]
                });
            }                   
            wincolumn.show(document.body);
            FusionCharts('columncut2').setXMLUrl(url);
            /*
                // Un-comment this code for fast resize
                win.addListener('resize', function (anda, w, h) {
                    FusionCharts('linked-chart').resizeTo(w -16, h - 71);
                });
             */
        }
//        FusionCharts.debugMode._enableFirebugLite();

        function showrowcut(url){            
            if(!winrow){
                var myChart1 = new FusionCharts( "Charts/MSCombi2D.swf", "rowcut2", "100%", "100%", "0", "1" );
                myChart1.render("rowcut");                
                winrow = new Ext.Window({
                    applyTo:'row-container',
                    layout:'fit',
                    width:520,
                    height:352,
                    closeAction:'hide',
                    plain: true,
                    items: new Ext.TabPanel({
                        applyTo: 'rowcut',
                        autoTabs:true,
                        activeTab:0,
                        deferredRender:false,
                        border:false
                    }),
                    buttons: [{
                        text: '关闭',
                        handler: function(){
                            winrow.hide(document.body);
                        }
                    }]
                });          
            }
            FusionCharts('rowcut2').setXMLUrl(url);                
            winrow.show(document.body); 
            var w = FusionCharts('rowcut2').width;
            var h = FusionCharts('rowcut2').height;
            if(w = Number.NaN)
                {
                    w = winrow.height;
                    h = winrow.height;
                }
                
            
            FusionCharts('rowcut2').resizeTo(w +1,h+1);
            FusionCharts('rowcut2').resizeTo(w-1,h-1);
             
                  
            //}
            //FusionCharts('rowcut2').setXMLUrl(url);
            //winrow.show(this);
            /*
                // Un-comment this code for fast resize
                win.addListener('resize', function (anda, w, h) {
                    FusionCharts('linked-chart').resizeTo(w -16, h - 71);
                });
             */
        }
        var item1 = new Ext.Panel({
                title: '图层',
                cls:'empty'
            });
            var item2 = new Ext.Panel({
                title: '电力设备台账检索与管理',     
                //html: '<iframe src="../public/MFleft_Module.aspx" style="overflow:auto;width:100%;height:100%;" frameborder="0" />',                    
                //layout:'anchor',
                //autoScroll:true,
                cls:'empty'
            });
            var item3 = new Ext.Panel({
                title: '巡检审核',
                html: '<iframe src="about:blank" style="overflow:auto;width:100%;height:100%;" frameborder="0" />',
                layout:'anchor',
                autoScroll:true,
                cls:'empty'                
            });

            var item4 = new Ext.Panel({
                title: '其他工具', 
                layout: 'border',
                html: '<div id="editbar" style="top:0px;position:absolute;" class="olControlEditingToolbar">',
                cls:'empty'
            });           
            var item5 = new Ext.Panel({
                title: '规划方案查看',
                cls:'empty'
            });
            var functionsGridData = [
                ['CalculateHuffman','<img src="images/directional_arrows.gif" />','计算'],
                ['ErlangB','<img src="images/directional_arrows.gif" />','Erlang B表'],
                ['SF_Cbmx','<img src="images/directional_arrows.gif" />','传播模型表'],
                ['SF_Llys','<img src="images/directional_arrows.gif" />','链路预算表']
            ];
            var functionsGridStore = new Ext.data.SimpleStore({
                fields: [
                    {name: 'vaule'},
                    {name: 'ico'},
                    {name: 'text'}
                ]
            });
            functionsGridStore.loadData(functionsGridData);
            var widtharray = [360,610,630,850];
            function functionsgridrowclick (grid, rowindex, e){
                var responsetext = functionsGridData[rowindex][0];
                var win = new Ext.Window({
                    title: functionsGridData[rowindex][2],
                    collapsible:true,
                    titleCollapse:true,
                    layout: 'fit',
                    width:widtharray[rowindex],
                    height:500,
                    html: '<iframe id="iframe-' + responsetext + '"src="Tools/'+responsetext+'.html" style="overflow:auto;width:100%;height:100%;" frameborder="0"></iframe>'
                });
                win.show();
            }
            var functionsgrid = new Ext.grid.GridPanel({
	            hideHeaders: true,
	            autoHeight: true,
	            //height: 300,
	            store: functionsGridStore,
	            columns: [
		            //{header: 'pic', width: 80,dataIndex: 'ico'},
		            {header: 'text',width: 246, dataIndex: 'text'}
	            ],
	            listeners: {
		            rowclick: functionsgridrowclick
	            }
            });
            var item6 = new Ext.Panel({
                title: '其他工具',
                
                //autoScroll: true,
		        //frame: true,
                //cls:'empty',
                items: [functionsgrid]
            });
        var toctree = null;
        //设置图层可见不可见
        function setlayervisible(layername,oldlayers,visible){
            layername = Ext.util.Format.uppercase(layername);
            oldlayers = Ext.util.Format.uppercase(oldlayers);
            if(visible){
                if(oldlayers.indexOf(layername) != -1){
                    return;
                }
                else{                    
                    oldlayers += "," + layername;
                    var newlayers = '';//devicelayername + "," + towerlayername + "," + overlinelayername;
                    if(oldlayers.indexOf(overlinelayername) != -1)
                        newlayers += overlinelayername + ",";
                    if(oldlayers.indexOf(towerlayername) != -1)
                        newlayers += towerlayername + ",";                    
                    if(oldlayers.indexOf(devicelayername) != -1)
                        newlayers += devicelayername + ",";    
                    if(newlayers.length > 0)
                        return newlayers.replace(/,$/,'');
                }
            }
            else{
                return oldlayers.replace(layername +',','').replace(layername,'');
            }
        }
    function getTocTree(){	
	    var treenode = new Ext.tree.TreeNode({expanded:true,allowDrop:false});

            var basenode = new Ext.tree.TreeNode({text:"背景图层",expanded:true,draggable:false,allowDrop:false           });
            var wmsnode = new Ext.tree.TreeNode({text:"电网",expanded:true,draggable:false,allowDrop:false});
            basenode.on("contextmenu",function(node,e){});
            wmsnode.on("contextmenu",function(node,e){});
            treenode.appendChild(basenode);
            treenode.appendChild(wmsnode);
            var layersnum = map.getNumLayers();
            for(var i = layersnum - 1; i >= 0; i--){
            	var layer = map.layers[i];
            	var layernode = null;
            	if(layer.isBaseLayer){
            		var name1 =  (layer == map.baseLayer)?layer.name + "-背景":layer.name;
            		layernode = new Ext.tree.TreeNode({
            			text:name1 ,            			
            			            	            		draggable:false,
            			            	            		allowDrop:false,
            	            		allowDrag:false,
            			qtip :'双击更换背景图层'           			
            			}
            		);
            	    layernode.on('dblclick', function(node,e){
            			if (node.text.indexOf('-背景')!=-1) return;
            			node.setText( node.text.replace("-背景","") + "-背景");
            			var layer = map.getLayersByName( node.text.replace("-背景",""))[0];
    					if(layer.isBaseLayer){
    						map.setBaseLayer(layer);
    						if (layer.name=="广东省地图")
            			        map.getControl('overviewmap').ovmap.setBaseLayer(map.getControl('overviewmap').layers[0]);
            			    else
            			        map.getControl('overviewmap').ovmap.setBaseLayer(map.getControl('overviewmap').layers[1]);
    					}            					            					
            			if(node.nextSibling!= null){
					        node.nextSibling.setText(node.nextSibling.text.replace("-背景",""));
				        }
				        if(node.previousSibling != null){
					        node.previousSibling.setText(node.previousSibling.text.replace("-背景",""));
				        }
            		});
            		layernode.on("contextmenu",function(node,e){});
            		basenode.appendChild(layernode);
            	}
            	else if (layer.isWMSLayer){
            	    layernode = new Ext.tree.TreeNode({
            	        text: "设备",
            	        checked:false,
            	        draggable: false,
            	        allowDrop:false
            	    });
            	    layernode.on("checkchange",function(node, ischecked){
            	        var layers = overlinelayer.params.LAYERS;            	        
            	            layers = setlayervisible(devicelayername,layers,ischecked);            	            
            	            overlinelayer.mergeNewParams({layers:layers});
            	    });
            	    layernode.on("contextmenu",function(node,e){});
            	    wmsnode.appendChild(layernode);
            	    layernode = new Ext.tree.TreeNode({
            	        text: "杆塔",
            	        checked:true,
            	        draggable: false,
            	        allowDrop:false
            	    });
            	    layernode.on("checkchange",function(node, ischecked){
            	         var layers = overlinelayer.params.LAYERS;            	        
            	            layers = setlayervisible(towerlayername,layers,ischecked);            	            
            	            overlinelayer.mergeNewParams({layers:layers});
            	    });
            	    layernode.on("contextmenu",function(node,e){});
            	    wmsnode.appendChild(layernode);            	    
            	    layernode = new Ext.tree.TreeNode({
            	        text: "架空线路",
            	        checked:true,
            	        draggable: false,
            	        allowDrop:false
            	    });
            	    layernode.on("checkchange",function(node, ischecked){
            	        var layers = overlinelayer.params.LAYERS;            	        
            	            layers = setlayervisible(overlinelayername,layers,ischecked);            	            
            	            overlinelayer.mergeNewParams({layers:layers});
            	        
            	    });
            	    layernode.on("contextmenu",function(node,e){});
            	    wmsnode.appendChild(layernode);
            	}            	
            	else if(layer.iscustom){
            	            		layernode = new Ext.tree.TreeNode({
            	            		checked:layer.getVisibility(),
            	            		draggable:true,
            	            		allowDrag:true,
            	            		allowDrop:false,
            	            		icon:layer.icon,            	            		
            			text:layer.name            			
            			}
            		);
            		layernode.on("checkchange",function(node,ischecked){
            					map.getLayersByName(node.text)[0].setVisibility(ischecked);
            					Ext.Ajax.request({
            					    url:'aspx/configlayerdefine.aspx?visible='+ischecked+'&layername='+encodeURI(node.text)
            					});
            				});
            		layernode.on("contextmenu",function(node,e){
            			var  treeMenu = new Ext.menu.Menu( {
		        	items : [new Ext.menu.Item( {
		                	text : '设置图例',
		                	iconCls : 'delete',
		                	handler : function(){
		                	    createSetLegendMenu(node);
		                	}
		            	})
		            	]
			    	});	
		 		var coords = e.getXY();
	    			treeMenu.showAt([coords[0], coords[1]]);       
            			
            		});            
            		olnode.appendChild(layernode);
            	}
            }                        
            toctree = new Ext.tree.TreePanel({
		        useArrows: true,
		        autoScroll: true,
		        animate: true,
		        enableDD: true,
		        containerScroll: true,
		        border: false,	
		        rootVisible:false,	
		        root: treenode
		    }
            );                        
            return toctree;
        }
        function centerAt(x,y){
             map.setCenter(new OpenLayers.LonLat(x,y).transform(pdis,pgoogle));
             var point = new OpenLayers.Geometry.Point(x,y).transform(pdis,pgoogle);
             hightLight(point.toString());
        }
        function hightLight(wkt){            
            var vector = new OpenLayers.Format.WKT().read(wkt);
            vector.style = GeoStyle.focus;
            drawlayer.removeAllFeatures();
            drawlayer.addFeatures(vector);
        }
        function zoomTo(wkt){
            var array = new OpenLayers. Format.WKT().read(wkt);                       
            map.zoomToExtent(array.geometry.getBounds().transform(pdis,pgoogle));
            hightLight(wkt);
        }
        //用Extjs生成信息框树结构
        function getInfoTree()
        {            
            
             infoTree = new Ext.tree.TreePanel({
	        useArrows: true,
	        autoScroll: true,
	        animate: true,
	        enableDD: true,
	        containerScroll: true,
	        border: false,	
	        rootVisible:false,	
	        dataUrl:'../public/GetTreeData.ashx',
	        root:{
	        nodeType:'async',
	        text:'root',
	        draggable:false,
	        id:'src'
	        }
		    });    
		    
            return infoTree;
        }
        //退出到登录页
        function toLogin()
        {
            if(confirm('确定要退出系统吗？'))
                window.location.href= "../login.aspx";            
        }   
        var infopanel,center;    
        function init() {     
            //左侧工具栏                  
            var accordion = new Ext.Panel({
                region:'west',
                margins:'0',
                split:true,
                collapsible: true,
                width: 250,
                minSize: 0,         // defaults to 50 
                maxSize: 250,
                minWidth:0,
                maxWidth:250,
                layout:'accordion',
                items: [item1, item2]
            });
            //信息框
            infopanel = new Ext.Panel({ // raw element
                region:'south',      
                minHeight:0,
                //maxHeight:'100%',
                split:true,
                closable:true,
                //collapsible: true,
                //collapsed:true,
                margins:'0',
                style:'z-index:999',
                html:'<iframe id="ContFrame" name="ContFrame" width="100%" height="100%" scroll="true" src="about:blank"/>'
            });
           //地图框
            var mapcontainer = new Ext.Panel({
                id:"mapc",
                    region:'center',
                    margins:'0',
                    cls:'empty',
                    bodyStyle:'background:#f1f1f1',
                    html:'<div id="map" style="width:100%;height:100%;border:0px solid red"><div id="output" style="background-color: white; position: absolute; bottom: 20px;left: 0px;"></div><div id="coords" style="background-color: white; position: absolute; bottom: 0px;left: 0px;z-index:999"></div></div>'
                    //<div id="overviewmap" style="position: absolute; background-color: white;height:200px; width: 200px;bottom: 0px;left: 0px; z-index: 999;border-right:2px solid gray;border-top:2px solid gray;"></div><div id="overviewmapbox" style="position: absolute; height:50px; width: 50px;bottom: 75px;left: 75px; z-index: 999;border:1px solid red;"></div>
                    //<div id="scaleline" style="position: absolute; bottom: 0px;right: 200px; z-index: 999;"></div>
            });
            //中央显示区域，包含了地图和信息框
             center = new Ext.Panel({
                    id:"mapcenter",
                    region:'center',
                    layout:'border',
                    margins:'0',
                    cls:'empty',
                    bodyStyle:'background:#f1f1f1',
                    items:[mapcontainer,infopanel]
            });
            //整体页面布局，包含上方的title区域，左侧工具栏和中央显示区域。
            var viewport = new Ext.Viewport({
                layout:'border',
                items:[
                new Ext.Panel({ // raw element
                region:'north',
                minHeight:80,
                maxHeight:80,
                margins:'0',
                //html: ' <p style="font-size:50; font-family: 隶书; text-align: center"><%Response.Write(SysSettings.GetHeadTitle());%> <span title="当前登录的用户"; style="font-size: 11pt;font-family: 宋体; color:Black;float:left;text-align:right ">欢迎您，<%=Session["_UserName"]%>！</span><a href="#" onclick="toLogin(); return false;" title="退出"><img src="../images/Main/Exit.gif" alt="退出" border="0" align="right"/></a></p>', //电网状态分析系统 改为：<%Response.Write(SysSettings.GetHeadTitle());%>
                //html:'<input type="button" value="退出系统" style="position:absolute;right:50px;top:50px;width:75px;height:30px" onclick="toLogin(); return false;"/><img src="../images/Main/主界面Banner高架.jpg" style="background-color:#99FF00;"/><label title="当前登录的用户"; style="font-size: 11pt;font-family: 宋体; color:Black;position:absolute;right:150px;top:54px;width:200px;height:30px;background-color:transparent;border:0;">欢迎您，<%=Session["_UserName"]%>！',
                html:'<div style="background-color: rgb(100, 217, 235);text-align:center;"><a href="#" onclick="toLogin(); return false;" title="退出"><img src="../images/Main/按钮背景图片.png" alt="退出" border="0" style="position:absolute;right:50px;top:50px;width:75px;height:30px" /></a><img src="../images/Main/主界面Banner高架.jpg" style="margin:auto"/><label title="当前登录的用户"; style="font-size: 11pt;font-family: 宋体; color:Black;position:absolute;right:135px;top:54px;width:170px;height:30px;background-color:transparent;border:0;">欢迎您，<%=Session["_UserName"]%>！</div>',
                height:90,
                bodyStyle:'background-color:#D9E7F8'
            }), 

                    accordion, center]
            });        
	    var wms = new OpenLayers.Layer.TileCacheCustom("永康市地图",
                [
                //"tiles/10/",0.0006866455078125*2,
                 "tiles/11/",
                 "tiles/12/",
                 "tiles/13/",
                 "tiles/14/",
                 "tiles/15/",
                 "tiles/16/",
                 "tiles/17/",
                 "tiles/18/"
                 ],
                "basic",
                {
                    serverResolutions: [0.0006866455078125,0.0006866455078125/2,0.0006866455078125/4,0.0006866455078125/8,0.0006866455078125/16,0.0006866455078125/32,0.0006866455078125/64,0.0006866455078125/128]
                }
            );     
        

        
        map = new OpenLayers.Map(
            'map',
            {                
                controls:[new OpenLayers.Control.PanZoomBar(),new OpenLayers.Control.ScaleLine({geodesic:true})],
                projection: pgoogle,
                displayProjection: pdis, 
                units: "m", 	                 
                numZoomLevels: 8,
                serverResolutions: [0.0006866455078125,0.0006866455078125/2,0.0006866455078125/4,0.0006866455078125/8,0.0006866455078125/16,0.0006866455078125/32,0.0006866455078125/64,0.0006866455078125/128],
                maxResolution: 0.0006866455078125,
                maxExtent: new OpenLayers.Bounds(-180,-90,180,90),
                restrictedExtent: new OpenLayers.Bounds(119.520935706,28.506912328,120.585200654,29.334847569),
                eventListeners: {
                        "mousemove":function(event){var latlon = map.getLonLatFromPixel(event.xy);document.getElementById('coords').innerHTML = latlon.lon.toFixed(5) + "," + latlon.lat.toFixed(5);}
                    }
            }
        );       
                    
        map.addLayer(wms);
            overlinelayer = new OpenLayers.Layer.WMS(
                "电力线",
                geoserverurl,
                {
                    layers: 'TAB_OVERLINE,TAB_TOWER',
                    srs: 'EPSG:4326',
                    format: 'image/png',
                    transparent: 'true',
                    titled: 'true'
                },
                {
                    buffer: 0,
                    tileSize:new OpenLayers.Size(512,512),
                    isBaseLayer: false,
                    isWMSLayer: true,
                    visibility: true,
                    displayOutsideMaxExtent: true
                }
            );
            map.addLayer(overlinelayer);                          
            drawlayer = new OpenLayers.Layer.Vector( "DrawLayer");                         
            map.addLayer(drawlayer);
            
            noeditvlayer = new OpenLayers.Layer.Vector( "不能修改的矢量层");
            map.addLayer(noeditvlayer);
            vlayer = new OpenLayers.Layer.Vector( "Editable");
            
            //vlayer.events.register("beforefeaturemodified" , null, function(obj){return;obj.feature.attributes.state = 'modify'; obj.feature.style=GeoStyle.update;vlayer.drawFeature(obj.feature);});
            //vlayer.events.register("afterfeaturemodified", null, function(obj){obj.feature.attributes.state = 'modify'; obj.feature.style=GeoStyle.update;vlayer.drawFeature(obj.feature);}); 
            vlayer.events.register("featuremodified", null, function(obj){obj.feature.attributes.state = 'modify'; obj.feature.style=GeoStyle.update;vlayer.drawFeature(obj.feature);}); 
            //vlayer.events.register("sketchcomplete", null, function(obj){obj.feature.toState('add'); obj.feature.style=GeoStyle.insert;vlayer.drawFeature(obj.feature);});                                                    
            map.addLayer(vlayer);
            

            var panmap = new OpenLayers.Control.MouseDefaults();
            //多边形选择
            var control1=new OpenLayers.Control.DrawFeature(drawlayer,OpenLayers.Handler.RegularPolygon,{handlerOptions:{sides:4,irregular:true},displayClass:'olControlTowerSelector',eventListeners:{featureadded:function(fea){drawlayer.removeAllFeatures();drawlayer.addFeatures(fea.feature);queryTowerByPolygon(fea.feature);}},title:"划多边形查询杆塔信息"});                        
            var control2=new OpenLayers.Control.DrawFeature(drawlayer,OpenLayers.Handler.RegularPolygon,{handlerOptions:{sides:4,irregular:true},displayClass:'olControlOverLineSelector',eventListeners:{featureadded:function(fea){drawlayer.removeAllFeatures();drawlayer.addFeatures(fea.feature);queryOverlineByPolygon(fea.feature);}},title:"划多边形查询线路信息"});                                    
//            var control4=new OpenLayers.Control.DrawFeature(vlayer, OpenLayers.Handler.Point, {title:'增加杆塔','displayClass': 'olControlDrawFeaturePoint'});
//            var control5=new OpenLayers.Control.DrawFeature(vlayer, OpenLayers.Handler.Path, {title:'增加线路','displayClass': 'olControlDrawFeaturePath'});
//            var control6=new OpenLayers.Control.DrawFeature(vlayer, OpenLayers.Handler.Polygon, {title:'增加变电站','displayClass': 'olControlDrawFeaturePolygon'});            
//            var control7=new OpenLayers.Control.DragFeature(vlayer,{title:'移动杆塔',onComplete:function(feature,pixel){if(feature.data.featureid) {feature.style=GeoStyle.update;feature.data.action = 'modify';vlayer.drawFeature(feature);}}});
            var control8=new OpenLayers.Control.ModifyFeature(vlayer,{title:'移动'});
            var control9=new OpenLayers.Control.Button({title:'保存',displayClass: "olControlSaveFeatures", trigger: savemodify});            
            var control10=new OpenLayers.Control.DrawFeature(drawlayer, OpenLayers.Handler.Point, {title:'断面分析',displayClass: 'olControlDrawFeaturePoint',eventListeners:{featureadded:function(fea){drawlayer.removeAllFeatures();drawlayer.addFeatures(fea.feature);ColumnCutAnalysis(fea.feature);}}});
            var control11=new OpenLayers.Control.DrawFeature(drawlayer, OpenLayers.Handler.Point, {title:'立面分析',displayClass: 'olControlDrawFeaturePoint',eventListeners:{featureadded:function(fea){drawlayer.removeAllFeatures();drawlayer.addFeatures(fea.feature);RowCutAnalysis(fea.feature);}}});
            var control12=new OpenLayers.Control.Button({title:'清除',displayClass: "olControlClearFeatures", trigger: function(){vlayer.removeAllFeatures();noeditvlayer.removeAllFeatures();drawlayer.removeAllFeatures();}});
            toolbar =new OpenLayers.Control.Panel({displayClass:'olControlGISToolbar',defaultControl:panmap});
            toolbar.addControls([panmap,control1,control2,control8,control9,control10,control11,control12]);
            map.addControl(toolbar);  
//            //增加标注层                                           
//            markerlayer = new OpenLayers.Layer.Text("标注", {extractStyles:true,defaultStyles:{graphicWidth:15,graphicHeight:15},projection:"EPSG:4326"} );                         
//            markerlayer.drawMarker = function(marker) {
//                var px = this.map.getLayerPxFromLonLat(marker.lonlat);
//                if (px == null) {
//                    marker.display(false);
//                } else {
//                    if (!marker.isDrawn()) {
//                        var markerImg = marker.draw(px);
//                        var div = document.createElement("DIV");
//                        var indexwidth =  10;
//                        var indexheight = 10;
//                        function getdiv(color){
//                            var div1 = document.createElement("DIV");
//                            div1.style.width = indexwidth + "px";
//                            div1.style.height = indexheight + "px";
//                            div1.style.backgroundColor = color;   
//                            div1.style.fontSize='2px';
//                            return div1;                         
//                        };
//                        var count = 0;
//                        for(var color in marker.feature.data){    
//                            if(color.toLowerCase().indexOf('rate')!=-1)                        
//                                {
//                                    count++;
//                                    div.appendChild(getdiv("#" + marker.feature.data[color]));
//                                }
//                        }                                                
//                        div.style.position = 'absolute';
//                        div.style.width = indexwidth + "px";
//                        div.style.height = indexheight * count + "px";
//                        div.style.border = '0px solid blue';
//                        div.style.left = px.x + "px";
//                        div.style.top =  px.y + "px";
//                        div.style.fontSize='2px';          
//                        this.div.appendChild(markerImg);
//                        this.div.appendChild(div);
//                        marker.div = div;
//                    } else if(marker.icon) {
//                        marker.icon.moveTo(px);
//                        marker.div.style.left = px.x + "px";
//                        marker.div.style.top = px.y + "px";
//                    }
//                }
//            };
//            markerlayer.removeMarker = function(marker) {
//                if (this.markers && this.markers.length) {
//                    if(marker.div)this.div.removeChild(marker.div);
//                    OpenLayers.Util.removeItem(this.markers, marker);
//                    marker.erase();
//                    
//                }
//            };
            //map.addLayer(markerlayer);
//            map.addControl(new OpenLayers.Control.MousePosition({element:document.getElementById('coords')}));                        
//            scaleline
//			var overviewmaplayer = new OpenLayers.Layer.TileCache("永康市地图",
//                ["tiles/11/",
//                 "tiles/12/",
//                 "tiles/13/",
//                 "tiles/14/",
//                 "tiles/15/"
//                 ],
//                "basic",
//                {
//                    serverResolutions: [0.0006866455078125,0.0006866455078125/2,0.0006866455078125/4,0.0006866455078125/8,0.0006866455078125/16]
//                }
//            );     

	                     
            
	

//            var mapOptions = {
//                resolutions: [1222.99245234375, 611.496226171874, 305.748113085937, 152.874056542968, 76.4370282714842, 38.21851413574219, 19.109257067871095, 9.554628533935547, 4.777314266967774, 2.388657133483887, 1.1943285667419434, 0.5971642833709717],
//                maxExtent: new OpenLayers.Bounds(-20037700, -20037700, 20037700, 20037700),
//                maxResolution: 1222.99245234375,
//                projection: pgoogle,
//                displayProjection: pdis,
//                numZoomLevels: 12,				
//                units: "m"
//            };

//            var overviewlayers = [overviewmaplayer];
//            try{                    
//                var gsatoverview = new OpenLayers.Layer.Google(
//                    "Google影像",
//                    {'sphericalMercator': true,type:G_HYBRID_MAP, numZoomLevels: 19}
//                    );
//                overviewlayers = [gsatoverview,overviewmaplayer];
//            }
//            catch(e){}
//            var controlOptions = {
//                id: 'overviewmap',
//				layers: overviewlayers,//gsatoverview
//                size: new OpenLayers.Size(180, 180),
//                minRatio: 8,
//				maxRatio: 8,
//                mapOptions: mapOptions
//            };
            //var overview = new OpenLayers.Control.OverviewMap(controlOptions);
            
            

            //map.addControl(overview);

            //overview.maximizeControl();

            map.setCenter(new OpenLayers.LonLat(120.05951, 28.89807).transform(pdis,pgoogle),1);                                   
            
            item1.add(getTocTree());
            item1.doLayout();
            item2.add(getInfoTree());
            item2.doLayout();
	        function resize(){
	           	    var center = map.getCenter();
	            	var zoom = map.getZoom();
	            	map.zoomToMaxExtent();
	            	map.moveTo(center,zoom);	            	
	        }
	   }	        
    </script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" scrolling='no'>
    </button>
    <div id="row-container" class="x-hidden">
        <div class="x-window-header">
        </div>
        <div id="rowcut" style="height:100%">
        </div>
    </div>
    <div id="column-container" class="x-hidden">
        <div class="x-window-header">
        </div>
        <div id="columncut" style="height:100%">
        </div>
    </div>
</body>
</html>
